<?php

namespace App\Sms;

use App\Sms\Contracts\Sms;
use Log;



class JtSms implements Sms
{

    public function sendTmplSms($phone,$tmpl,$data,$extend=null)
    {
        return true;


    }

    /**
     * @param $phone
     * @param $content
     * @return bool
     */
    public function sendSms($phone, $content)
    {
        $sms_conf = config('sms');
        $conf = $sms_conf['gateways']['JtSms'];
        $id = $conf['id'];
        $pwd = $conf['pwd'];

        $url="http://service.winic.org:8009/sys_port/gateway/index.asp?";
        $data = "id=%s&pwd=%s&to=%s&Content=%s&time=";
        $id = urlencode(iconv("utf-8","gb2312",$id));
        $pwd = $pwd;
        $to = $phone;
        $content = urlencode(iconv("UTF-8","GB2312",$content));
        $rdata = sprintf($data, $id, $pwd, $to, $content);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$rdata);
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
        $result = curl_exec($ch);
        curl_close($ch);
        $arr = explode('/',$result);
        if($arr[0]=='000') {
            return true;
        } else {
            Log::error("发送短信失败：".$result);
            return false;
        }
    }
}
